const user = {
	state: {
		userToken: uni.getStorageSync('userToken') || '',
		userInfo: uni.getStorageSync('userInfo') || '',
		appLanguage: uni.getStorageSync('appLanguage') || uni.getLocale(),
		languageEnum: {
			'en': 'en_US',
			'zh-Hans': 'zh_CN',
			'zh-Hant': 'zh_HK',
			'id_ID': 'id_ID',
			'ko_KR': 'ko_KR',
			'th_TH': 'th_TH',
			'vi_VN': 'vi_VN',
			'pt_BR': 'pt_BR',
			'es_ES': 'es_ES',
			'ja': 'ja_JP',
		},
		languageList: [
			[{
					name: 'English',
					id: 'en'
				},
				{
					name: '简体中文',
					id: 'zh-Hans'
				},
				{
					name: '繁体中文',
					id: 'zh-Hant'
				},
				{
					name: 'Indonesia',
					id: 'id_ID'
				},
				{
					name: 'ภาษาไทย',
					id: 'th_TH'
				},
				{
					name: 'Tiếng Việt',
					id: 'vi_VN'
				},
				{
					name: '한국어',
					id: 'ko_KR'
				},
				{
					name: '日本語',
					id: 'ja'
				},
				{
					name: 'Español',
					id: 'es_ES'
				},
				{
					name: 'Português',
					id: 'pt_BR'
				}
			]
		]
	},
	mutations: {
		SET_userToken: (state, userToken) => {
			state.userToken = userToken
		},
		SET_userInfo: (state, userInfo) => {
			state.userInfo = userInfo
		},
		SET_changeLang(state, appLanguage) {
			uni.setStorageSync('appLanguage', appLanguage)
			state.appLanguage = appLanguage
		},
	},
	actions: { //异步操作mutation
		remove_userInfo({
			commit
		}, userInfo) {
			uni.removeStorageSync('userInfo');
			commit('SET_userInfo', userInfo)
		},
		set_userToken({
			commit
		}, userToken) {
			uni.setStorageSync('userToken', userToken);
			commit('SET_userToken', userToken)
		},
		set_userInfo({
			commit
		}, userInfo) {
			uni.setStorageSync('userInfo', userInfo);
			commit('SET_userInfo', userInfo)
		},
		remove_logout({
			commit
		}, rememberPassword) {
			uni.removeStorageSync('userInfo');
			uni.removeStorageSync('userToken');
			commit('SET_userToken', '')
			commit('SET_userInfo', '')
		},
		changeLang({
			commit
		}, appLanguage) {
			console.log(appLanguage);
			uni.setLocale(appLanguage)
			commit('SET_changeLang', appLanguage)
		},
	}
}

export default user